package org.shoukaiseki.common.random;

import org.apache.commons.lang3.RandomUtils;
import org.shoukaiseki.common.utils.DateUtils;

import java.text.ParseException;
import java.util.Date;

/**
 *
 **/
public class RandomDate {


    // 起始时间为       1970-01-01 08:00:00
    // 这里最大值默认是 2088-08-08 00:00:00
    // 时间最大值是 Long.MAX_VALUE=292278994-08-17 15:12:55
    public static Date nextDate(){
        return nextDate(0L, DateUtils.lastDateMilliseconds);
    }

    public static Date nextDate(String startTimeStr,String endTimeStr){
        try {
            Date startDate = org.apache.commons.lang3.time.DateUtils.parseDate(startTimeStr);
            Date endDate = org.apache.commons.lang3.time.DateUtils.parseDate(endTimeStr);
            return nextDate(startDate.getTime(),endDate.getTime());
        } catch (ParseException e) {
            throw new RuntimeException("",e);
        }

    }

    public static Date nextDate(Long startTime,Long endTime){
        return new Date(RandomUtils.nextLong(startTime,endTime));
    }

}
